//
//  NewsController.m
//  Notice
//
//  Created by CPX on 2018/9/12.
//  Copyright © 2018年 CPX. All rights reserved.
//

#import "NewsController.h"
#import "NewsCell.h"

/**
 系统通知详情页
 @author yzl
 */
@interface NewsController ()<UITableViewDelegate,UITableViewDataSource>


@property (nonatomic,strong) UITableView *table;
@property (nonatomic,strong) NSArray *list;
@property (nonatomic, strong) UIImageView *emptyView;

@end

@implementation NewsController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)initViews{
    self.table = [[UITableView alloc] initWithFrame:CGRectMake(0, NavHeight, kScreenWidth, kScreenHeight - NavHeight) style:UITableViewStylePlain];
    self.table.delegate = self;
    self.table.dataSource = self;
    self.table.rowHeight = UITableViewAutomaticDimension;
    self.table.estimatedRowHeight = 80;
    self.table.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.view.backgroundColor = UIColorHex(#f4f4f4);
    self.table.backgroundColor = UIColorHex(#f4f4f4);
    //    self.table.tableHeaderView = self.headerView;
    [self.view addSubview:self.table];
    
    MJRefreshNormalHeader *he = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(reloadData)];
    he.lastUpdatedTimeLabel.hidden = YES;
    he.stateLabel.hidden = YES;
    self.table.mj_header = he;
//    self.table.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadData)];
    [self.table.mj_header beginRefreshing];
    
    self.emptyView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"no_content_img"]];
    [self.view addSubview:self.emptyView];
    self.emptyView.center = CGPointMake(self.view.width/2, self.view.height/2);
}
- (void)loadData{
    
    [NoticeApi getNoticeListWithSuccess:^(id response) {
        [self.table.mj_header endRefreshing];
        self.list = [NSArray yy_modelArrayWithClass:[NewsModel class] json:response];
        [self.table reloadData];
        self.emptyView.hidden = self.list.count != 0;
    } failure:^(NSError *error) {
        self.emptyView.hidden = self.list.count != 0;
        [MBProgressTool showTextForView:self.self.view text:error.userInfo[@"msg"]];
    }];
}

#pragma mark - table


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.list.count;
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NewsCell *cell = [NewsCell cellWithTable:tableView];
//    cell.notice = self.list[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}

@end
